package com.rpc.example.spring.customer;

import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;

@AutoConfiguration
// @EnableConfigurationProperties(value = {RpcReferenceConfiguration.class})
public class RpcReferenceAutoConfiguration implements EnvironmentAware {

    @Bean
    public RpcReferencePostProcessor rpcReferencePostProcessor() {
        RpcReferenceConfiguration rpcReferenceConfiguration = new RpcReferenceConfiguration();
        rpcReferenceConfiguration.setRegisterAddress(environment.getProperty("consumer.rpc.registerAddress"));
        rpcReferenceConfiguration.setRegistryType(Byte.parseByte(environment.getProperty("consumer.rpc.registryType")));
        return new RpcReferencePostProcessor(rpcReferenceConfiguration);
    }

    private Environment environment;

    @Override
    public void setEnvironment(Environment environment) {
        this.environment = environment;
    }
}
